Icon Capture
Volume Number: 5
Issue Number: 12
Column Tag: Color Workshop
Related Info: Color Quickdraw
Capture Color Icons 
By Steve and Patricia Sheets, Herdon, VA
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
Color Icons: Editor and cicnCapture
This month’s Color Quickdraw column consists of less talk and more code. In the
last column, the building block data structures needed in order to use and understand
color icons were discussed. A new Rez/Derez resource source template was given that
allowed easier creation of ‘cicn’ resource (Color Icon template resource). While the
template is helpful in learning and understanding color icons, and is an excellent way
to present color icons on the written page, most users would prefer to use some
graphic base tool to create a color icon. This column contains a quick review of the two
color icon editors freely available to the development community. Then, the column
will present this months source code, ‘cicnCapture’, a FKEY utility designed to capture
an image on the screen and convert it to a color icon resource.
Public Domain Color Icon Editors
There are two different color icon editors available in Public Domain. The very
first editor released was the application ‘CIcon Edit’ by Ben Haller of AppleSauce
Designs. ‘CIcon Edit’ allows the users to edit color icons of 32 by 32 pixels size that
have up to 16 separate colors. The editor can import a ‘cicn’ resource, a ‘ICON’
resource or a ‘ICN#’ resource. This feature makes the tool exceptionally good at
coloring existing icon art work. ‘CIcon Edit’ itself is the easiest to use, with a good
command set to manipulate the image (move, roll, flip, rotate). This tool has been
around the longest (latest version I’ve seen is 1.1) and is virtually bug proof.
Unfortunately, the application is lacking in certain areas. This editor is unable to edit
a color icon that is any other size than 32 by 32 pixels and 16 colors. There is no
method of adjusting any other settings of the resource. ‘CIcon Edit’ does not have a
palette of tools (ala MacPaint); the user draws the image a pixel at a time. Also, the
load command does not give a list of all the ‘cicn’ resources of the target file. Thus, the
user has to keep track of all ‘cicn’ and their ID numbers himself. To be really
productive with this tool, the user needs to work ResEdit.
The other PD color icon editor solves this problem by being a ResEdit extension.
‘ResWare’ by Frédéric Miserey of None Corp in Paris consists of certain resources
that the user copies into his ResEdit application (replacing some existing ones). Then
the user can use ResEdit directly to observe, create and edit ‘cicn’ resources. This
utility is a more powerful editor then ‘CIcon Edit’. ‘ResWare’ has a complete tool
palette that includes pen, eraser, fill bucket, lasso, and other rectangle commands.
The editor can use single color patterns when drawing. There is no practical limit to
the size of the color icon, nor the number of colors. Also the editor allows the user to
change other portions of the ‘cicn’ resource including horizontal and vertical size,
component count, component size and pixmap method (Chunky, Chunky/Planar or
Planar). However the editor is still in beta form (latest version I’ve seen is 1.0b4)
and has caused numerous crashes. ‘ResWare’ has no import feature, and the editor,
while more powerful, is not as easy to use for beginners as ‘CIcon Edit’.
Importing Images into Color Icons
While both editors are useful in creating color icons, they both suffer from a
common fault. They do not allow easy import of an image on the screen into a ‘cicn’
resource. At first, it may not seem as if this is a problem. Of course, the editor will
only be used to create a ‘cicn’ resource. However, this is not always the case. Look at
what happened with original Quickdraw and the creation of ‘ICON’ and ‘ICN#’
resources. Even though there were a few icon editors, many non-technical users
created their images with the more powerful Paint and Draw programs. Then they
handed the complete art work to a programmer, expecting him to be able to use it
directly. The programmer had no way to directly transfer an art document into a
‘ICON’ or ‘ICN#’ resource. In many cases, the programmer had to reenter the image
into the icon editor one pixel at a time. To solve this problem, many programmers
created various Icon-Grapper types of utilities. These utilities, usually Desk
Accessories or FKEYs, allowed the programmer to capture any portion of the screen
and convert it into an icon resource. Since it captured an image on the screen and did
not need to directly convert any type of document, these utilities would work with any
Paint or Draw application.
A user who wanted to convert a Pixel Paint or MacDraw // image into a ‘cicn’
resource would have the identical problem. The problem is further complicated, since
the user would have to worry not only about the 32 by 32 pixel image, but would have
to import a color list, a mask and a black and white icon. I had this problem. The
graphic designer of my latest project presented the technical team with a group of
Pixel Paint files, each one having a dozen or so images on it. It would have taken hours
of work to reenter the images using one of the color icon editors. That estimate was
assuming that the artwork was the finished product, and not going to be revised. This
started looking like a potential nightmare.
cicnCapture
The solution to this problem is being provided as the sample source code.
‘cicnCapture’ is an FKEY utility that can capture a 32 by 32 pixel image of the screen,
containing up to 256 different colors, and create a ‘cicn’ resource that contains this
image. The code uses the Quickdraw call, GetCPixel, to determine the color of each
pixel in the image. Since the code uses this call instead of reading the screen PixMap
directly, it will work on any depth or type of screen or monitor as long as Color
Quickdraw is installed. Once the image has been captured, the information is saved out
to a specified resource file.
Using this utility on our software project, it took a few minutes to import all of
the color images into ‘cicn’ resource. ‘CIcon Edit’ and ‘ResEdit’ were used afterward,
but mainly to make sure the images had the correct ID number, and that they were
centered on the 32 by 32 pixel icon.
Next Column
Anyone remember the game, ‘Daleks’? This application was one of the first, and
best, Public Domain games around. Next issue’s sample code will be ‘Color Daleks’.
The program will show how to directly draw and manipulate color icons. Various color
drawing modes will be explained, as well as some animation speed up tricks.
{ cicnCapture - Color Icon Capture FKEY }
{ by Steve Sheets for MacTutor 9/3/89 }
{ FKEY is normal saved to resource type ‘FKEY’, ID = 7 }
{ This FKEY captures a 32 by 32 Pixel section of the screen and
converts it into a ‘cicn’ resource (Color Icon }
{ template). When the user activates the Function Key and click
somewhere on the screen, that portion of the }
{ screen is recorded (colors and pixels) and a cicn handle is
created. Remember a cicn handle is different than }
{ an actual Color Icon handle. The cicn handle/resoure is a template
for a Color Icon. The Color Quickdraw }
{ command, GetCIcon, uses the cicn resource to determine how to make
a Color Icon. }
{ FKEY is written in Think’s Lightspeed Pascal 2.0. }
unit cicnCapture;
interface
uses
Quickdraw, ToolIntf;
{ FKEY (function key) code resources must have be an unit with a
single externally reference procedure called }
{ ‘Main’.}
procedure Main;
implementation
procedure Main;
{ The ‘cicn’ resource consists of three variable length parts. The
first part contains the Pixmap info, the Black }
{ & White Icon and the Mask. The second part contains the Color
Lookup table (ie. list of colors used in the }
{ cicn). The size of this part is dependent on the number of
different colors in the cicn. The last part of the }
{ resource is the pixel data. The size of this is dependent on the
number of different colors in the cicn. If }
{ there are 2 to 16 colors, the pixel info can be stored in a 4 bit
pixel maip, if the number of colors is 17 to }
{ 256, then the info must be stored in a 8 bit pixel map. Given the
fact this FKEY only captures 32 by 32 cicn, }
{ the size of the first part is fixed, while the size of the third
part is one of two possible fixed sizes. }
IconData = packed array[0..31] of LongInt;
{ First part of cicn resource for a 32 by 32 pixel cicn.}
cicnData = record
baseAddr: LongInt;
rowbytes: INTEGER;
bounds: Rect;
pmVersion: INTEGER;
packType: INTEGER;
packSize: LongInt;
hRes: LongInt;
vRes: LongInt;
pixelType: INTEGER;
pixelSize: INTEGER;
cmpCount: INTEGER;
cmpSize: INTEGER;
planeBytes: LongInt;
pmTable: LongInt;
pmReserved: LongInt;
MaskBaseAddr: LongInt;
MaskRowBytes: INTEGER;
MaskBounds: Rect;
BMapBaseAddr: LongInt;
BMapRowBytes: INTEGER;
BMapBounds: Rect;
IconData: LongInt;
theMask: IconData;
theBMap: IconData;
ctSeed: LongInt;
ctFlags: INTEGER;
ctSize: INTEGER;
end;
cicnPtr = ^cicnData;
{ 2nd part (CLUT) of cicn resource for 32 by 32 pixel cicn. }
CTableData = packed array[0..255] of ColorSpec;
CTablePtr = ^CTableData;
{ 3rd part of cicn resource for 8 bit, 32 by 32 pixel cicn. }
pixel8Data = packed array[0..31, 0..31] of 0..255;
pixel8Ptr = ^pixel8Data;
{ 3rd part of cicn resource for 4 bit, 32 by 32 pixel cicn. }
pixel4Data = packed array[0..31, 0..15] of 0..255;
pixel4Ptr = ^pixel4Data;
var
thePos: Point;
thePixel8: pixel8Data;
theNumColors: INTEGER;
theIcon: IconData;
theColorList: packed array[0..255] of RGBColor;
theCICN: Handle;
{ Tell us if Color Quickdraw is installed on machine. }
function IsColorQuickdraw: BOOLEAN;
const
ROM85Loc = $28E;
TwoHighMask = $C000;
WordPtr = ^INTEGER;
var
Wd: WordPtr;
begin
Wd := POINTER(ROM85Loc);
IsColorQuickdraw := (BitAnd(Wd^, TwoHighMask) = 0);
end;
{ Sets cursor to show an upper left portion of a square.}
procedure InitSquare;
var
count: INTEGER;